import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'id',
    label: '主键',
  },
  {
    component: 'Input',
    fieldName: 'userName',
    label: '用户姓名',
  },
  {
    component: 'Input',
    fieldName: 'csdnUsername',
    label: 'csdn用户名',
  },
  {
    component: 'Input',
    fieldName: 'csdnUserAccount',
    label: 'csnd账号',
  },
  {
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_NORMAL_DISABLE 便于维护
      options: getDictOptions('sys_normal_disable'),
    },
    fieldName: 'userStatus',
    label: '账号状态(0-启用1-停用)',
  },
  {
    component: 'Textarea',
    fieldName: 'remark',
    label: '备注',
  },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '主键',
    field: 'id',
  },
  {
    title: '用户姓名',
    field: 'userName',
  },
  {
    title: '关联账号id',
    field: 'userId',
  },
  {
    title: 'csdn用户名',
    field: 'csdnUsername',
  },
  {
    title: 'csnd账号',
    field: 'csdnUserAccount',
  },
  {
    title: 'csdn密码',
    field: 'csdnPassword',
  },
  {
    title: '客户端ID',
    field: 'client',
  },
  {
    title: '账号状态(0-启用1-停用)',
    field: 'userStatus',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.SYS_NORMAL_DISABLE 便于维护
        return renderDict(row.userStatus, 'sys_normal_disable');
      },
    },
  },
  {
    title: '备注',
    field: 'remark',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '主键',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '用户姓名',
    fieldName: 'userName',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '关联账号id',
    fieldName: 'userId',
    component: 'Input',
    rules: 'required',
  },
  {
    label: 'csdn用户名',
    fieldName: 'csdnUsername',
    component: 'Input',
    rules: 'required',
  },
  {
    label: 'csnd账号',
    fieldName: 'csdnUserAccount',
    component: 'Input',
    rules: 'required',
  },
  {
    label: 'csdn密码',
    fieldName: 'csdnPassword',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '客户端ID',
    fieldName: 'client',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '账号状态(0-启用1-停用)',
    fieldName: 'userStatus',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_NORMAL_DISABLE 便于维护
      options: getDictOptions('sys_normal_disable'),
    },
    rules: 'selectRequired',
  },
  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
    rules: 'required',
  },
];
